package ext.opensource.netty.server.example.mqtt;

import com.alibaba.fastjson.JSON;

import ext.opensource.netty.server.mqtt.MqttServer;
import ext.opensource.netty.server.mqtt.api.InternalSend;
import ext.opensource.netty.server.mqtt.common.InternalMessage;

public class MqttCustomCommunicate extends BaseMqttCustom implements InternalSend, MqttServerRecvice {
	@Override
	public void init(final MqttServer mqttServer) {
		super.init(mqttServer);
		mqttServer.initMqtt().setInternalSend(this);
	}

	@Override
	public void internalSend(final InternalMessage msg) {
		processInternalSend(JSON.toJSONString(msg));
	}

	protected void processInternalSend(final String msg) {
	}

	public boolean processInternalRecvice(final InternalMessage msg) {
		return mqttServer.internalRecvice().processInternalRecvice(msg);
	}

	@Override
	public boolean processServerRecviceMesage(final String message) {
		final InternalMessage msgObj = JSON.parseObject(message, InternalMessage.class);
		return processInternalRecvice(msgObj);
	}
}
